package com.game.league.entrance.user.table;

import com.game.base.utils.DecimalUtil;

import cn.bmob.v3.BmobUser;

/**
 * 映射类 - 用户表: 自由添加用户属性
 * Created by Su on 2019/5/22.
 */
public class User extends BmobUser {
    private String nickname;  // 昵称
    private Integer age;  // 年龄
    private Integer gender;  // 性别  1 = 男性，2 = 女性，0 = 未知
    private String address; // 用户当前位置
    private String avatar;     //头像
    private String signAt;  // 用户签到时间  yyyy-MM-dd

    private float coinToday;      // 今日点券
    private float coinHistory;      // 历史点券
    private float coinRemain;      // 剩余点券

    public String getNickname() {
        return nickname;
    }

    public User setNickname(String nickname) {
        this.nickname = nickname;
        return this;
    }

    public Integer getAge() {
        return age;
    }

    public User setAge(Integer age) {
        this.age = age;
        return this;
    }

    public Integer getGender() {
        return gender;
    }

    public User setGender(Integer gender) {
        this.gender = gender;
        return this;
    }

    public String getAddress() {
        return address;
    }

    public User setAddress(String address) {
        this.address = address;
        return this;
    }

    public String getAvatar() {
        return avatar;
    }

    public User setAvatar(String avatar) {
        this.avatar = avatar;
        return this;
    }

    public String getSignAt() {
        return signAt;
    }

    public void setSignAt(String signAt) {
        this.signAt = signAt;
    }

    public float getCoinToday() {
        return coinToday;
    }

    public void setCoinToday(float coinToday) {
        this.coinToday = coinToday;
    }

    public float getCoinHistory() {
        return coinHistory;
    }

    public void setCoinHistory(float coinHistory) {
        this.coinHistory = coinHistory;
    }

    public float getCoinRemain() {
        return coinRemain;
    }

    public void setCoinRemain(float coinRemain) {
        this.coinRemain = coinRemain;
    }

    /**
     * 更新用户点券数据
     */
    public void addCoinNum(User user, float num) {
        user.setCoinToday(DecimalUtil.addFloat(user.getCoinToday(), num));
        user.setCoinHistory(DecimalUtil.addFloat(user.getCoinHistory(), num));
        user.setCoinRemain(DecimalUtil.addFloat(user.getCoinRemain(), num));
    }

    public boolean reduceCoinNum(User user, float num) {
        if (user.getCoinRemain() < num) {
            return false;
        }
        user.setCoinRemain(DecimalUtil.reduceFloat(user.getCoinRemain(), num));
        return true;
    }

    @Override
    public String toString() {
        return "User{" +
                "nickname='" + nickname + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                ", address='" + address + '\'' +
                ", avatar='" + avatar + '\'' +
                ", signAt='" + signAt + '\'' +
                ", coinToday=" + coinToday +
                ", coinHistory=" + coinHistory +
                ", coinRemain=" + coinRemain +
                '}';
    }
}
